package com.jingli.pile.domain;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jingli.pile.constant.Constants;
import com.jingli.pile.util.HmacMd5Signature;
import com.jingli.pile.util.SeqUtils;
import com.jingli.pile.util.SequenceGenerator;

import java.time.LocalDateTime;

@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
public class CommonDataResult {
    @JsonProperty(value = "Ret")
    private Integer ret;
    @JsonProperty(value = "Msg")
    private String msg;
    @JsonProperty(value = "Data")
    private String data;
    @JsonProperty(value = "Sig")
    private String sig;
    @JsonProperty(value = "PlatformID")
    private String platformId;
    @JsonProperty(value = "TimeStamp")
    private String timeStamp;
    @JsonProperty(value = "Seq")
    private String seq;

    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getSig() {
        return sig;
    }

    public void setSig(String sig) {
        this.sig = sig;
    }

    public String getPlatformId() {
        return platformId;
    }

    public void setPlatformId(String platformId) {
        this.platformId = platformId;
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getSeq() {
        return seq;
    }

    public void setSeq(String seq) {
        this.seq = seq;
    }

    public static CommonDataResult success(String data, String sig){
        CommonDataResult commonDataResult = new CommonDataResult();
        commonDataResult.setPlatformId(Constants.OWN_PLATFORM_ID);
        commonDataResult.setSeq(SeqUtils.getUniqueInstance().getSeq());
        commonDataResult.setTimeStamp(LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss"));
        commonDataResult.setRet(0);
        commonDataResult.setMsg("请求成功");
        commonDataResult.setData(data);
        commonDataResult.setSig(sig);
        return commonDataResult;
    }
    public static CommonDataResult failure(int code,String msg,String data,String sig){
        CommonDataResult commonDataResult = new CommonDataResult();
        commonDataResult.setPlatformId(Constants.OWN_PLATFORM_ID);
        commonDataResult.setSeq(SeqUtils.getUniqueInstance().getSeq());
        commonDataResult.setTimeStamp(LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss"));
        commonDataResult.setRet(code);
        commonDataResult.setMsg(msg);
        commonDataResult.setData(data);
        commonDataResult.setSig(sig);
        return commonDataResult;
    }
}
